package com.whxd.framework.common.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.whxd.framework.security.FrameworkUserDetails;
import com.whxd.framework.security.SecurityUtils;

/**
 * 
 * @author 张世鹏
 * @since 2013-6-19
 */
public class ContextUtils {

	/**
	 * 获取当前线程当前请求的request
	 * 
	 * @author 张世鹏
	 * @since 2013-6-19
	 * @return HttpServletRequest
	 */
	public static HttpServletRequest getRequest() {
		RequestAttributes ra = RequestContextHolder.getRequestAttributes();
		HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
		return request;
	}

	/**
	 * 获取当前线程当前请求的session
	 * 
	 * @author 张世鹏
	 * @since 2013-6-19
	 * @return HttpSession
	 */
	public static HttpSession getSession() {
		return getRequest().getSession();
	}

	public static FrameworkUserDetails getCurrentSecurityUser() {
		return SecurityUtils.getCurrentSecurityUser();
	}
}
